package com.cloudserver.springboot.service.impl;

import com.cloudserver.springboot.Constants.Sql;
import com.cloudserver.springboot.bean.*;
import com.cloudserver.springboot.bean.Character;
import com.cloudserver.springboot.dao.CharacterMapper;
import com.cloudserver.springboot.dao.UserMapper;
import com.cloudserver.springboot.service.PermissionService;
import com.cloudserver.springboot.vo.PermissionMenu;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zqq
 * @create 2020-10-08 10:05
 */
public class PermissionServiceImpl implements PermissionService {

    @Resource
    private UserMapper userMapper;

    @Resource
    private CharacterMapper characterMapper;

    @Override
    public List<PermissionMenu> doPermissionMenu(String account) {

        return null;
    }

    /**
     * @Description: getUserIdByAccount  通过账户查询user表的主键id
     * @param: [account] 账户
     * @return: java.lang.Integer  如果查询到则返回主键，福州返回-1
     * @auther: zqq
     * @date: 20/10/9 15:17
     */
    @Override
    public Integer getUserIdByAccount(String account) {
        UserExample userExample = new UserExample();
        userExample.createCriteria().andAccountEqualTo(account);
        List<User> users = userMapper.selectByExample(userExample);
        if (users.size() == Sql.SELECTONE){
            return users.get(0).getId();
        }
        return -1;
    }


    /**
     * @Description: getAllById 根据userId查好像character的内容
     * @param: [userId]
     * @return: com.cloudserver.springboot.bean.Character
     * @auther: zqq
     * @date: 20/10/9 17:29
     */
    @Override
    public Character getAllById(Integer userId) {
        List<Character> characters =  characterMapper.getAllById(userId);
        if (characters.size() == Sql.SELECTONE){
            return characters.get(0);
        }
        return null;
    }
}
